<?php
class Model {
	protected $sql = null;
	
	public function __construct() {
		if(DB_NAME != '' && DB_USER != '' && DB_HOST != '') {
			try {
				$this->sql = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASS);
				$this->sql->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
			} catch(Exception $ex) {
				throw new Exception($ex->getMessage(), 501);
			}
		}
	}
	
	protected function requireDB() {
		if(!$this->sql) throw new Exception('No database connection. Please setup database settings in "framework/config/config.php"', 501);
	}
}

?>